package com.huage_06.lesson_05;

import java.util.*;

public class PokerDemoPro {
    public static void main(String[] args) {
        //装牌
        /* ♠2....
           ♥2....
           ♣2....
           ♦2.....
         */
        String[] colors = {"♠","♥","♣","♦"};
        String[] number = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};

        int index = 0;
        HashMap<Integer,String> hm = new HashMap<Integer,String>();
        ArrayList<Integer> poker = new ArrayList<Integer>();
        for (String s : number) {
            for (String color : colors) {
                hm.put(index,color + s);
                poker.add(index);
                index++;
            }
        }
        hm.put(index,"大王");
        poker.add(index);
        index++;
        hm.put(index,"小王");
        poker.add(index);

        //洗牌
        Collections.shuffle(poker);

        //发牌 玩家收牌并排序
        TreeSet<Integer> play1 = new TreeSet<Integer>();
        TreeSet<Integer> play2 = new TreeSet<Integer>();
        TreeSet<Integer> play3 = new TreeSet<Integer>();
        TreeSet<Integer> Dpoker = new TreeSet<Integer>();
        for (int i=0;i<poker.size();i++){
            Integer p = poker.get(i);
            if(i>=poker.size()-3){
                Dpoker.add(p);
            }if(i%3==0){
                play1.add(p);
            }if(i%3==1){
                play2.add(p);
            }if(i%3==2){
                play3.add(p);
            }
        }

        //看牌
        lookPoker("底牌",Dpoker,hm);
        lookPoker("玩家一",play1,hm);
        lookPoker("玩家二",play2,hm);
        lookPoker("玩家三",play3,hm);


    }
    //看牌
    /*
        返回值类型：void
        参数：String playName,TreeSet<Integer> poker,HashMap<Integer,String> hm
     */
    public static void lookPoker(String playName,TreeSet<Integer> poker,HashMap<Integer,String> hm){
        StringBuilder sb = new StringBuilder();
        for (Integer num : poker){
            String p = hm.get(num);
            sb.append(p).append(" ");
        }
        String playPoker = sb.toString();
        System.out.println(playName+"的牌是："+playPoker);
    }
}
